package com.lwq.controller;

import java.io.File;

import javax.swing.JFileChooser;

import com.lwq.cocos.ProjectInfoAdpter;
import com.lwq.util.Constance;
import com.lwq.view.CreateProDialog;
import com.lwq.view.DesignView;
import com.lwq.view.LeftEditorView;

public class FileController extends BaseController
{
	private static String mFilePath = null;
	private static String mFileName = null;
	private static String mProType = null;
	
	public static void newCocosCommand()
	{
		mProType = Constance.COCOS_LABLE;
		ProjectInfoAdpter.getInstance().newProInfo(Constance.COCOS_LABLE);
		new CreateProDialog("Create "+Constance.COCOS_LABLE+" Project");
	}

	public static void newNodeCommand()
	{
		mProType = Constance.NODE_LABLE;
		ProjectInfoAdpter.getInstance().newProInfo(Constance.NODE_LABLE);
		new CreateProDialog("Create "+Constance.NODE_LABLE+" Project");
	}
	
	public static void newSenceCommand()
	{
		mProType = Constance.SCENE_LABLE;
		ProjectInfoAdpter.getInstance().newProInfo(Constance.SCENE_LABLE);
		new CreateProDialog("Create "+Constance.SCENE_LABLE+" Project");
	}
	
	public static void newSpriteCommand()
	{
		mProType = Constance.SPRITE_LABLE;
		ProjectInfoAdpter.getInstance().newProInfo(Constance.SPRITE_LABLE);
		new CreateProDialog("Create "+Constance.SPRITE_LABLE+" Project");
	}
	
	public static void newLayoutCommand()
	{
		mProType = Constance.LAYOUT_LABLE;
		ProjectInfoAdpter.getInstance().newProInfo(Constance.LAYOUT_LABLE);
		new CreateProDialog("Create "+Constance.LAYOUT_LABLE+" Project");
	}
	
	public static void CreatProject(String path){
		mFilePath = path;
		mFileName = mFilePath.substring(mFilePath.lastIndexOf(File.separator)+1);
		ProjectInfoAdpter.getInstance().getProInfo().setProjectName(mFileName);
		LeftEditorView.getInstance().reLoadData();
	}
	
	public static void newActionCommand()
	{
		
	}
	


	public static void openProjectCommand(){
		JFileChooser fc = new JFileChooser();
		fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
		int returnVal = fc.showOpenDialog(DesignView.getInstance());
		String path = null;
		if(fc.getSelectedFile()!= null)
		{
			path = fc.getSelectedFile().getPath();
			if(path != null){
				ProjectInfoAdpter.getInstance().decodeProInfo(path);
				mFilePath = path;
				mFileName = mFilePath.substring(mFilePath.lastIndexOf(File.separator)+1);
				LeftEditorView.getInstance().reLoadData();
			}
		}
	}
	
	public static void saveFileCommand()
	{
		ProjectInfoAdpter.getInstance().saveProInfo(mFilePath);
		
	}
	
}
